package tgc.edu.examxy.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import tgc.edu.examxy.entity.Feedback;
import tgc.edu.examxy.entity.SysUser;
import tgc.edu.examxy.security.User2;
import tgc.edu.examxy.service.FeedbackService;
import tgc.edu.examxy.service.SysUserService;

@Controller
@RequestMapping(value = "/feedback")
public class FeedbackController {
	@Autowired
	private FeedbackService service;
	
	private SysUserService sysservice;
	@RequestMapping(value ="/manage")
	private String manage() {
		return "feedback/manage";
	}
	@RequestMapping(value = "/save")
	@ResponseBody
	private void save(String opinion,String proposal) {
		SecurityContext ctx = SecurityContextHolder.getContext();
		Authentication auth = ctx.getAuthentication();
		User2 user = (User2) auth.getPrincipal();
		SysUser sysuser = sysservice.findByUsername(user.getUsername());
		Feedback feed = new Feedback();
		feed.setOpinion(opinion);
		feed.setProposal(proposal);
		feed.setSysuserId(sysuser.getId());
		service.save(feed);
	}
	
}
